<?php

class Model_keywords extends MY_Model {

    protected $_table = 'keywords';
    protected $_primaryKey = 'id';

    public function __construct() {
        parent::__construct();
        $this->db = $this->load->database('default', true);
        $this->setDb($this->db);
    }

    /**
     * 根据sql语句查询结果集
     * @param string $sql
     * @param array $params
     * @return array
     */
    public function query($sql, $params = array()) {
        $query = null;
        if (empty($params)) {
            $query = $this->db->query($sql);
        } else {
            $query = $this->db->query($sql, $params);
        }
        return empty($query) ? array() : $query->result_array();
    }

    /**
     * 根据sql语句执行处理
     * @param string $sql
     * @param array $params
     * @return array
     */
    public function queryForUpdate($sql, $params = array()) {
        $query = null;
        if (empty($params)) {
            $query = $this->db->query($sql);
        } else {
            $query = $this->db->query($sql, $params);
        }
        return $this->db->affected_rows();
    }

}
